import 'package:flutter/material.dart';

import 'LikeAnimalIcon.dart';

class LikeAnimalIconImplicit extends StatefulWidget {
  final FinishListener mFinishListener;

  LikeAnimalIconImplicit({required this.mFinishListener});

  @override
  _LikeAnimalIconImplicitState createState() => _LikeAnimalIconImplicitState();
}

class _LikeAnimalIconImplicitState extends State<LikeAnimalIconImplicit> {
  double _opacity = 0.0;
  double _scale = 1.0;
  double _iconSize = 100.0;

  @override
  void initState() {
    super.initState();
    
    // 分阶段执行动画
    // 第一阶段：淡入
    Future.delayed(Duration.zero, () {
      setState(() {
        _opacity = 1.0;
      });
    });
    
    // 第二阶段：放大
    Future.delayed(Duration(milliseconds: 1500), () {
      setState(() {
        _scale = 1.5;
        _iconSize = 150.0;
      });
    });
    
    // 第三阶段：淡出
    Future.delayed(Duration(milliseconds: 3500), () {
      setState(() {
        _opacity = 0.0;
      });
    });
    
    // 动画完成回调
    Future.delayed(Duration(seconds: 5), () {
      widget.mFinishListener(widget);
    });
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedOpacity(
      opacity: _opacity,
      duration: Duration(milliseconds: 1500),
      curve: Curves.easeIn,
      child: AnimatedContainer(
        duration: Duration(milliseconds: 2000),
        curve: Curves.elasticOut,
        width: _iconSize,
        height: _iconSize,
        child: Transform.scale(
          scale: 1,
          alignment: Alignment.center,
          child: Icon(
            Icons.favorite,
            color: Colors.blue,
            size: 100, // 固定大小，由外部容器控制
          ),
        ),
      ),
    );
  }
}
